package cm.day14.Test3;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class PersonTest {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        //创建Class对象
        Class<Person> clz = Person.class;
        //
        Constructor<Person> constructor = clz.getConstructor(String.class, int.class);
        //
        Person ps = constructor.newInstance("光头强", 23);
        System.out.println(ps);
        //
        Method method = clz.getMethod("setName", String.class);
        //
        String result = (String) method.invoke(ps, "熊大");
      //  System.out.println(result);
        //
        Field age = clz.getDeclaredField("age");
        //
        age.setAccessible(true);
        //
        age.set(ps,23);
        //
        System.out.println(ps);
//


    }
}
